﻿using System.Drawing;
using Firestarter.DB.Schema.BO;
using FireStarterModeller.UI.CodeGeneration;
using FireStarterModeller.UI.DatabaseConnection;
using Habanero.Base;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.Faces.Base;
using Habanero.Faces.Win;
using DockStyle=System.Windows.Forms.DockStyle;

namespace FireStarterModeller.UI
{
    public class DBConnectionInfoMapper : ExtendedComboBoxMapper
    {
        private ClassDef _classDef;
        private IControlFactory _controlFactory;
        public DBConnectionInfoMapper(IExtendedComboBox ctl, string propName, bool isReadOnly, IControlFactory controlFactory)
            : base(ctl, propName, isReadOnly, controlFactory)
        {

        }
        protected override IBOGridAndEditorControl GetIBOGridAndEditorControl()
        {
            IBOGridAndEditorControl iboGridAndEditorControl = ((DatabaseConnectionGridAndEditorControl)PopupForm.Controls[0]).BOGridAndEditorControl;
            return iboGridAndEditorControl;
        }

        private DatabaseConnectionGridAndEditorControl SetupDatabaseConnectionInfoPanel()
        {
            var createConnectionGridAndEditor = new DatabaseConnectionGridAndEditorControl();
            var businessObjectCollection = Broker.GetBusinessObjectCollection<DatabaseConnectionInfo>("");
            createConnectionGridAndEditor.DatabaseConnectionInfos = businessObjectCollection;
            return createConnectionGridAndEditor;
        }

        public override void ShowPopupForm()
        {
            PopupForm = ControlFactory.CreateForm();
            PopupForm.Height = 500;
            PopupForm.Width = 700;
            PopupForm.MinimumSize = new Size(700, 500);
            PopupForm.StartPosition = FormStartPosition.CenterScreen;

            DatabaseConnectionGridAndEditorControl databaseConnectionGridAndEditorControl = new DatabaseConnectionGridAndEditorControl();
            databaseConnectionGridAndEditorControl = SetupDatabaseConnectionInfoPanel();
            databaseConnectionGridAndEditorControl.Dock = DockStyle.Fill;
            PopupForm.Controls.Add(databaseConnectionGridAndEditorControl);

        }


    }

}
